package com.softao.ming.gde.internal.ui.launcher;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

import com.softao.ming.gde.internal.ui.block.LocationTextBlock;

/**
 * 
 */
public class ConfigurationDataBlock extends AbstractGroupBlock {
	private LocationTextBlock mConfigurationLocation;
	
	/**
	 * @param tab
	 */
	public ConfigurationDataBlock(GwtLaunchTab tab) {
		super(tab);
	}

	@Override
	protected void createContent(Composite parent) {
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		parent.setLayout(layout);
		parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		mConfigurationLocation = new LocationTextBlock();
		mConfigurationLocation.createControl(parent);
	}

	@Override
	protected String getText() {
		return "Configuration";
	}

	@Override
	public void performApply(ILaunchConfigurationWorkingCopy configuration) {
		configuration.setAttribute("configurationLocation", mConfigurationLocation.getLocation());
	}
	
	
	@Override
	public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
		configuration.setAttribute("configurationLocation", "");
	}
	
	@Override
	public void initializeFrom(ILaunchConfiguration configuration)
			throws CoreException {
		mConfigurationLocation.setLocation(configuration.getAttribute("configurationLocation", ""));
	}
}
